<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * @property-read Collection<ChannelPeriod> $channelPeriods
 */
class Channel extends Model
{
    use HasDateTimeFormatter;

    const STATUS_ENABLE = 'enable';
    const STATUS_DISABLE = 'disable';

    /**
     * @return BelongsTo
     */
    public function platform(): BelongsTo
    {
        return $this->belongsTo(Platform::class);
    }

    /**
     * 时间段配置
     * @return HasMany
     */
    public function channelPeriods(): HasMany
    {
        return $this->hasMany(ChannelPeriod::class);
    }

    public static function getStatusOption(): array
    {
        return [
            self::STATUS_ENABLE => '启用',
            self::STATUS_DISABLE => '禁用',
        ];
    }

    public static function getStatusColorMap(): array
    {
        return [
            self::STATUS_ENABLE => 'success',
            self::STATUS_DISABLE => 'danger',
        ];
    }

    public static function getNameList()
    {
        $list = self::get();
        $data = [];
        foreach ($list as $item) {
            $data[$item->id] = $item->name;
        }
        return $data;
    }

}
